package com.whty.module.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.whty.common.annotation.Log;
import com.whty.common.enums.BusinessType;

import com.whty.web.core.base.BaseController;
import com.whty.framework.web.page.TableDataInfo;
import com.whty.system.domain.Garden;
import com.whty.system.service.IGardenService;
import com.whty.common.base.AjaxResult;

/**
 * 园茶 信息操作处理
 * 
 * @author mario
 * @date 2018-10-26
 */
@Controller
@RequestMapping("/module/garden")
public class GardenController extends BaseController
{
    private String prefix = "module/garden";
	
	@Autowired
	private IGardenService gardenService;
	
	@RequiresPermissions("module:garden:view")
	@GetMapping()
	public String garden()
	{
	    return prefix + "/garden";
	}
	
	/**
	 * 查询园茶列表
	 */
	@RequiresPermissions("module:garden:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Garden garden)
	{
		startPage();
        List<Garden> list = gardenService.selectGardenList(garden);
		return getDataTable(list);
	}
	
	/**
	 * 新增园茶
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存园茶
	 */
	@RequiresPermissions("module:garden:add")
	@Log(title = "园茶", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Garden garden)
	{		
		return toAjax(gardenService.insertGarden(garden));
	}

	/**
	 * 修改园茶
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Garden garden = gardenService.selectGardenById(id);
		mmap.put("garden", garden);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存园茶
	 */
	@RequiresPermissions("module:garden:edit")
	@Log(title = "园茶", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Garden garden)
	{		
		return toAjax(gardenService.updateGarden(garden));
	}
	
	/**
	 * 删除园茶
	 */
	@RequiresPermissions("module:garden:remove")
	@Log(title = "园茶", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(gardenService.deleteGardenByIds(ids));
	}
	/**
	 * 获取茶厂信息
	 * @return
	 */
	@GetMapping("/getGardenList")
	@ResponseBody
	public List<Garden> getGardenList(){
		List<Garden> garden = gardenService.getGarden();
		return garden;
	}
	   
//    /**
//     * 选择部门树
//     */
//    @GetMapping("/selectDeptTree/{teaGardenNum}")
//    public String selectDeptTree(@PathVariable("teaGardenNum") String teaGardenNum, ModelMap mmap)
//    {
//        mmap.put("dept", gardenService.selectProductByteaGardenNum(teaGardenNum));
//        return prefix + "/tree";
//    }
//
//    /**
//     * 加载部门列表树
//     */
//    @GetMapping("/treeData")
//    @ResponseBody
//    public List<Map<String, Object>> treeData()
//    {
//        List<Map<String, Object>> tree = gardenService.selectProductTree();
//        return tree;
//    }
	
}
